<template>
	<div v-if="!isLogin" class="default-page">
		<default-page :hint="hint"></default-page>
	</div>
</template>

<script>
	import {
		Toast
	} from 'vant';

	import {
		login_api
	}
	from '../../api/index.js';

	import DefaultPage from '../../components/DefaultPage.vue';

	export default {
		name: 'login',
		components: {
			DefaultPage
		},
		data() {
			return {
				isLogin: true,
				href: window.location.href,
				hint: '身份验证失败，请重新进入'
			}
		},
		created() {
			let token = this.getQueryVariable('token')
			if (token) {
				this.$store.commit('setToken', token)
				this.$router.replace('/home')
			} else {
				this.isLogin = false
			}
		},
		methods: {
			getQueryVariable(variable) {
				var query = this.href.slice(this.href.indexOf('?') + 1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return false;
			}
		}
	}
</script>

<style>
</style>
